<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="/grsun" prefix="grsun"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta charset="utf-8" />
<meta name="description" content="Mailbox with some customizations as described in docs" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
<%@ include file="/include/main_include.jsp"%>
<%@ include file="/include/form_include.jsp"%>
 
</head>
<body>
	<div class="modal-body" style="max-height: 716px;">
		<div id="divform" class="row mx-dialog-c bs_dialog open"> 
		   <form id="dataForm" class="form-horizontal" method="post"> 
		   <input type="hidden" id="foodId" name="foodId" value="${pd.foodId}"/>   
		   <input type="hidden" id="foodMenuId" name="foodMenuId" value="${pd.foodMenuId}"/>   
			 
			<div class="form-group col-lg-6 col-sm-6 col-xs-6">
		        <label class="control-label mx-group-title">名称</label>
		        <div class="mx-group-control" style="height:33px;">
					<input id="name" name="name" type="text" class="width-100 mx-input-group" style="height:33px;" value="${pd.name}">
		        </div>
		    </div>
		    <%-- <div class="form-group col-lg-6 col-sm-6 col-xs-6">
		        <label class="control-label mx-group-title">简短描述</label>
		        <div class="mx-group-control" style="height:33px;">
					<input id="subTitle" name="subTitle" type="text" class="width-100 mx-input-group" style="height:33px;" value="${pd.subTitle}">
		        </div>
		    </div> --%>
			<div class="form-group col-lg-6 col-sm-6 col-xs-6">
		        <label class="control-label mx-group-title">排序</label>
		        <div class="mx-group-control" style="height:33px;">
					<input id="sorts" name="sorts" type="number" class="width-100 mx-input-group" style="height:33px;" value="${pd.sorts}">
		        </div>
		    </div>
			<div class="form-group col-lg-6 col-sm-6 col-xs-6">
		        <label class="control-label mx-group-title">图片</label>
		        <div class="mx-group-control" style="height:100px;">
				        <div class="layui-upload">
				        <input type="hidden"  name="img"  id="hide1" >
						 <input class="layui-upload-file" type="file" accept="images" name="file">
						  <div class="layui-upload-list">
						    <img class="layui-upload-img" id="test1" src="${imagePath }${pd.img}">
						    <p id="demoText1"></p>
						  </div>
						</div> 
		        </div>
		    </div>
			 
			<div class="form-group col-lg-6 col-sm-6 col-xs-6">
		        <label class="control-label mx-group-title">是否多规格</label>
		        <div class="mx-group-control" style="height:33px;">
		        	<select id="isMulttag" name="isMulttag" class="width-100" style="height: 33px;">
								<option value="0">否</option>
								<option value="1">是</option>
						</select>
		        </div>
		    </div>
			<div class="form-group col-lg-6 col-sm-6 col-xs-6">
		        <label class="control-label mx-group-title">价格</label>
		        <div class="mx-group-control" style="height:33px;">
					<input id="price" name="price" type="number" class="width-100 mx-input-group" style="height:33px;" value="${pd.price}">
		        </div>
		    </div>
			<div class="form-group col-lg-6 col-sm-6 col-xs-6">
		        <label class="control-label mx-group-title">描述</label>
		        <div class="mx-group-control" style="height:33px;">
					<input id="foodDesc" name="foodDesc" type="text" class="width-100 mx-input-group" style="height:33px;" value="${pd.foodDesc}">
		        </div>
		    </div>
		 
		  </form>                  
		</div>
	</div>
	<script type="text/javascript">
	
	 var img="${pd.img}";
	 if(img==""){
		 $("#test1").attr("src","${imagePath }shop/onload.png");
	 }
	
	
	function uploadFile(upload,flag){
		 upload.render({
			    elem: '#test'+flag
			    ,size:10000
			    ,url: '${path}/image/upload.do?path=shop'
		    	,before: function(obj){
		    	      //预读本地文件示例，不支持ie8
		    	      obj.preview(function(index, file, result){
		    	        $('#test'+flag).attr('src', result); //图片链接（base64）
		    	      });
		    	 }
	    	    ,done: function(res){
	    	      //如果上传失败
	    	      if(res.code > 0){
	    	        return layer.msg('上传失败');
	    	      }else{
		    	      //上传成功
					$("#hide"+flag).val(res.url);	    	 
					return layer.msg('上传成功');
	    	      }
	    	    }
		 	});
	 }
	
	$(function() {
		layui.use('upload', function(){
			  var $ = layui.jquery;
			  upload = layui.upload;
			  uploadFile(upload,1);
		  });
 
		$('#dataForm').validate({
			submitHandler : function(form) {
				var index = parent.layer.getFrameIndex(window.name);
				$.uitools.showLoading();//打开处理中遮罩层
				$.ajax({
					cache : true,
					type : "POST",
					url : rootpath + '/hhFood/save.do',
					data : $('#dataForm').serialize(),
					error : function(request) {
						$.uitools.hideLoading();//关闭处理中遮罩层
						layer.msg('系统异常！', {
							icon : 2,
							time : 1000
						}, function() {
							parent.layer.close(index);
						})
					},
					success : function(data) {
						$.uitools.hideLoading();//关闭处理中遮罩层
						if (data.code==0) {
							layer.msg('提交成功！', {
								icon : 1,
								time : 1000
							}, function() {
								parent.layer.close(index);
								//刷新列表
								parent.foodTable.datagrid('reload');
							})
						} else {
							layer.msg('提交异常！', {
								icon : 2,
								time : 1000
							}, function() {
								parent.layer.close(index);
							})
						}
					}
				});
			},
			rules : {
				foodId : { required : true },
				name : { required : true },
				addTime : { required : true ,number : true},
				sorts : { required : true ,number : true},
				img : { required : true },
				businessId : { required : true },
				foodMenuId : { required : true },
				type : { required : true ,number : true},
				isMulttag : { required : true ,number : true},
				price : { required : true },
				foodDesc : { required : true },
				startTime : { required : true },
				endTime : { required : true },
				subTitle : { required : true }
			},
			messages : {
				foodId : { required : '请输入' },
				name : { required : '请输入名称' },
				addTime : { required : '请输入添加时间' },
				sorts : { required : '请输入排序' },
				img : { required : '请输入图片' },
				businessId : { required : '请输入商家id' },
				foodMenuId : { required : '请输入菜单id' },
				type : { required : '请输入类型' },
				isMulttag : { required : '请输入是否多规格' },
				price : { required : '请输入价格' },
				foodDesc : { required : '请输入描述' },
				startTime : { required : '请输入开始时间' },
				endTime : { required : '请输入结束时间' },
				subTitle : { required : '请输入二级title' }
			},
			// 失去焦点时不执行验证
			onfocusout : false,
			// 错误提示，错误对象
			errorPlacement : function(error, element) {
				// 1.错误信息，2提示位置，3同时提示多个错误
				layer.tips(error[0].innerText, element, {
					// 错误信息可以同时提示多个，...
					tipsMore : true,
					tips : [ 3, '#D16E6C' ]
				});
			}
		});
	});
	</script>
</body>
</html>
